import pygame, os, sys, time
from pygame.locals import *

import data.game as game

# start pygame
pygame.init()

# environment constants
WINDOWHEIGHT = 800
WINDOWWIDTH = 600
screen = pygame.display.set_mode((WINDOWHEIGHT,WINDOWWIDTH), 0, 32)
pygame.display.set_caption('Penalty Shootout Game')
background = pygame.image.load("data/img/menu.png").convert()
menufont = pygame.font.SysFont('Monospace', 48)
scores = []

def play():
	scores.append(game.playgame())

def printmenu():
	screen.blit(background, (0,0))
	
	menuline1 = "Space - Play Game"
	menuline2 = "Esc   - Quit/Scores"
	
	menuline1 = menufont.render(menuline1, 1, (255, 255, 255))
	menuline2 = menufont.render(menuline2, 1, (255, 255, 255))
	
	screen.blit(menuline1, (180, 450))
	screen.blit(menuline2, (180, 500))
	pygame.display.flip()

def mainMenu():
	global scores
			
	pressenter = menufont.render("PRESS A KEY", 1, (0, 200, 0))

	screen.blit(background, (0,0))
	screen.blit(pressenter, (230, 400))
	
	pygame.display.flip()
		
	while (pygame.event.wait().type is not KEYDOWN):
		pass
	
	printmenu()
	
	quitter = False
	while not quitter:
		
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exit()
				
			if event.type == KEYDOWN:
				if event.key == K_ESCAPE:
					quitter = True
				
				if event.key == K_SPACE:
					play()
					printmenu()	
		
	
	print "Player Scores:\n"
	scores.sort()
	
	i = 1
	for score in scores:
		print str(i) + ".	" + str(score) + "\n"
		i += 1
		
	pygame.time.wait(5000)

if __name__ == '__main__':
	mainMenu()
	pygame.quit()
	sys.exit()
